/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Facade;

import DAO.exceptions.NonexistentEntityException;
import Service.ServiceFactory;
import Service.exceptions.InvalidTypeOfServiceException;
import VO.UsuarioVO;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author David
 */
public class Facade{
    
    public UsuarioVO Login(String username) throws NonexistentEntityException{
        EntityManagerFactory emf = null;
        EntityManager em = null;
        UsuarioVO userVO = new UsuarioVO();
       
        try {
            emf = Persistence.createEntityManagerFactory("manuPU");
            em = emf.createEntityManager();
            userVO = ServiceFactory.createService(ServiceFactory.LOGIN).Login(username, em);
            if(userVO == null)
               throw new NonexistentEntityException("No existe la persona" + username);
        }
        
        finally {
            /*if(userVO==null) {
                userVO.setClave("incorrecto");
                userVO.setCorreo("incorrecto");
                return userVO;
            }*/
            if(em != null){
                em.clear();
                em.close();
            }
        }
        
        return userVO;
    }
}
    

